package cn.zcscloud.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class SqlSessionFactoryUtils {
    static SqlSessionFactory sqlSessionFactory;
    static {
        try {
            //加载mybatis配置文件
            InputStream resource = Resources.getResourceAsStream("mybatis-config.xml");
            //创建sql工厂
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
            /*//创建sqlSession对象
            SqlSession sqlSession = sqlSessionFactory.openSession();*/
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static SqlSessionFactory getSqlSessionFactory(){return sqlSessionFactory;}

}
